package logic

import (
	"context"
	"math/rand"
	"shuqi-novel/models/cache"
	"time"

	"shuqi-novel/userrpc/internal/svc"
	"shuqi-novel/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type SendSmsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSendSmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendSmsLogic {
	return &SendSmsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 手机短信
func (l *SendSmsLogic) SendSms(in *userrpc.SendSmsRequest) (*userrpc.SendSmsResponse, error) {
	// todo: add your logic here and delete this line

	code := rand.Intn(9000) + 1000
	//sms, err := pkg.SnedSms(in.Account, strconv.Itoa(code))
	//if err != nil {
	//	return nil, err
	//}
	//if sms.Code!=2{
	//	return nil, errors.New(sms.Msg)
	//}
	cache.Rdb.Set(l.ctx, "smsCode_"+in.Account, code, time.Minute*10)
	return &userrpc.SendSmsResponse{}, nil
}
